package cn.sytton.taffe.web.sys.controller;

import cn.sytton.taffe.web.sys.entity.AuthMenuTree;
import cn.sytton.taffe.web.sys.entity.MenuEntity;
import com.github.pagehelper.PageInfo;
import cn.sytton.taffe.framework.base.controller.BaseController;
import cn.sytton.taffe.framework.base.entity.PageParam;
import cn.sytton.taffe.web.sys.service.IMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单控制层
 *
 * @author skyrock
 */
@Tag(name = "菜单")
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys/menu")
public class MenuController extends BaseController {

    private final IMenuService menuService;

    @Operation(summary = "查询分页菜单列表")
    @Parameter(name = "pp", description = "分页参数对象", in = ParameterIn.QUERY, required = true)
    @GetMapping
    public PageInfo<MenuEntity> findPage(PageParam pp) {
        return menuService.findListPageOfXml(pp);
    }

    @Operation(summary = "查询单个菜单")
    @Parameter(name = "id", description = "菜单ID", in = ParameterIn.PATH, required = true)
    @GetMapping("/{id}")
    public MenuEntity findById(@PathVariable String id) {
        return menuService.findById(id);
    }

    @Operation(summary = "添加菜单")
    @PostMapping
    public void create(@RequestBody MenuEntity entity) {
        menuService.create(entity);
    }

    @Operation(summary = "更新菜单")
    @PostMapping("/update")
    public void update(@RequestBody MenuEntity entity) {
        menuService.update(entity);
    }

    @Operation(summary = "删除菜单", description = "body: 主键ID数组")
    @PostMapping("/delete")
    public void delete(@RequestBody String[] ids) {
        menuService.delete(ids);
    }

    @Operation(summary = "获取当前登录人的权限菜单树")
    @GetMapping("/my")
    public List<MenuEntity> findMyMenu(){
        return menuService.findMyMenu();
    }

    @Operation(summary = "获取所有菜单及权限")
    @GetMapping("/auth")
    public List<AuthMenuTree> findAuthMenu() {
        return menuService.findAuthMenu();
    }
}
